<?php

namespace Sharks\Core\Make;

use Sharks\Core\AppContext;
use Sharks\Core\Cfg\AppConfig;
use Sharks\Core\Support\Base\Arr;

abstract class Maker {

    abstract public function dev(AppContext $app);

    abstract public function server(AppContext $app);

    public function makers() {
        return null;
    }

    public static function exec(array $makers, AppContext $app, &$executed = array()) {
        foreach ($makers as $maker) {
            // 判断是否执行过，再执行
            if (!in_array($maker, $executed)) {

                // 先执行前置
                $m = new $maker();
                $pre = $m->makers();
                if (!empty($pre)) {

                    self::exec($pre, $app, $executed);
                }
                if (AppConfig::MODE_DEV == $app->mode()) {
                    $m->dev($app);
                }
                else {
                    $m->server($app);
                }
                array_push($executed, $maker);
            }
        }
    }

}